#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n;
	cin >> n;
	vector<int> ans(2 * n + 1, 0);
	vector<bool> vis(2 * n + 1, false);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			int x;
			cin >> x;
			ans[i + j] = x;
			vis[x] = true;
		}
	}
	for (int i = 1; i <= 2 * n; i++)
	{
		if (ans[i] != 0) cout << ans[i] << ' ';
		else
		{
			for (int j = 1; j <= 2 * n; j++)
			{
				if (!vis[j])
				{
					cout << j << ' ';
					vis[j] = true;
				}
			}
		}
	}
	cout << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}